package func

import java.io.File

/**
 * 函数字面量, 匿名函数, 高阶函数??
 *
 * filesHere0:
 * // https://stackoverflow.com/questions/7409502/what-is-the-difference-between-def-foo-and-def-foo-in-scala
 * // https://stackoverflow.com/questions/7600910/difference-between-function-with-parentheses-and-without
 * 无参方法/parameterless method
 * @author tzp
 * @since 2021/1/15
 */
object FileMatches {
  //函数字面量???偏应用函数???只是简单的省略了???
  def filesHere = (new File(".")).listFiles
  def filesHere0: Array[File] = (new File(".")).listFiles

  //标准而又正常的函数写法; 空圆括号方法
  def filesHere1(): Array[File] = (new File(".")).listFiles

  //标准而又正常的变量写法, 调用一个方法初始化而已; 这三个里只有这个值是固定的, 修改目录下文件多次调用不变.
  val filesHere2: Array[File] = (new File(".")).listFiles
  //private val filesHere3(): Array[File] = (new File(".")).listFiles //报错无法编译

  def main(args: Array[String]): Unit = {
    //filesHere0() //报错
    filesHere0(1) //数组第1个元素

    filesHere1() //
    //filesHere1(1) //报错
    filesHere1()(1)

    //filesHere2() //报错
    filesHere2(1) //

    //dummyFunc(filesHere0) //报错Required Function0 Found Array
    dummyFunc(filesHere1)
    //dummyFunc(filesHere2) //报错Required Function0 Found Array

  }

  private def dummyFunc(x: () => Array[File]) = x()
}
